package com.huike.web.controller.clues;

import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.service.TbClueTrackRecordService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 线索跟进记录Controller
 * @date 2023-04-22
 */
@Slf4j
@RestController
@RequestMapping("/clues/record")
@Api(tags = "线索跟进")
public class TbClueTrackRecordController extends BaseController {
    @Autowired
    private TbClueTrackRecordService tbClueTrackRecordService;

    /*
    * 查询线索跟进记录列表
    * */
    @ApiOperation("查询线索跟进记录列表")
    @GetMapping("/list")
    public TableDataInfo<List<TbClueTrackRecord>> recordList(@RequestParam("clueId")Long clueId){
        startPage();
        List<TbClueTrackRecord> list = tbClueTrackRecordService.recordList(clueId);
        System.out.println("list = " + list);
        return getDataTable(list);
    }

    /*
    * 获取线索跟进记录详细信息
    * */
    @ApiOperation("获取线索跟进记录详细信息")
    @GetMapping("/{id}")
    public AjaxResult getRecordById(@PathVariable Integer id){
        TbClueTrackRecord tbClueTrackRecord = tbClueTrackRecordService.getRecordById(id);
        return AjaxResult.success(tbClueTrackRecord);
    }

    /*
    * 新增线索跟进记录
    * */
    @ApiOperation("新增线索跟进记录")
    @PostMapping
    public AjaxResult addRecord(@RequestBody ClueTrackRecordVo clueTrackRecordVo){
        log.info(String.valueOf(clueTrackRecordVo));
        tbClueTrackRecordService.addRecord(clueTrackRecordVo);
        return AjaxResult.success();

        /*答案*/
        //线索跟进记录对象
        /*TbClueTrackRecord trackRecord=new TbClueTrackRecord();
        //把前端传来的数据拷贝到TbClueTrackRecord实体中
        BeanUtils.copyProperties(tbClueTrackRecord,trackRecord);
        trackRecord.setCreateTime(DateUtils.getNowDate());
        trackRecord.setCreateBy(SecurityUtils.getUsername());



        TbClue tbClue=new TbClue();
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setStatus("2"); //进行中
        tbClue.setId(tbClueTrackRecord.getClueId());
        return toAjax(tbClueTrackRecordService.insertTbClueTrackRecord(tbClue,trackRecord));*/
    }
}
